package com.gexiaobao.pigeon.ui.adapter

import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.ext.RxTextTool
import com.gexiaobao.pigeon.app.model.bean.BiddingHistoryResponse
import com.gexiaobao.pigeon.app.util.ImageLoaderManager
import com.gexiaobao.pigeon.databinding.ItemLayoutBiddingHistoryBinding

/**
 * @Author      : hxw
 * @Date        : 2024/11/12 10:31
 * @Describe    :
 */
class AdapterBiddingHistory(data: ArrayList<BiddingHistoryResponse>) :
    BaseQuickAdapter<BiddingHistoryResponse, DataBindBaseViewHolder>(R.layout.item_layout_bidding_history, data) {

    override fun convert(holder: DataBindBaseViewHolder, item: BiddingHistoryResponse) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemLayoutBiddingHistoryBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

        val tvItemUserPrice = holder.getView<AppCompatTextView>(R.id.tvItemUserPrice)
        RxTextTool.getBuilder("￥")
            .append(item.showPrice.toString()).setAppearance(60).setTextColor(ContextCompat.getColor(context, R.color.color_fe4542))
            .into(tvItemUserPrice)

        val ivUserHead = holder.getView<AppCompatImageView>(R.id.ivBidHistoryPrice)
        ImageLoaderManager.loadCircleImageFall(context, item.userAvatar, ivUserHead, R.mipmap.profilepic_str_1)

        val bgImage = if (holder.layoutPosition == 0) {
            R.mipmap.icon_be_in_the_lead
        } else {
            R.mipmap.icon_bidding_out
        }
        holder.setBackgroundResource(R.id.tvBidStatus, bgImage)
    }
}